home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JMenuItem;
- import com.sun.java.swing.JRadioButtonMenuItem;
- import com.sun.java.swing.LookAndFeel;
- import com.sun.java.swing.MenuElement;
- import com.sun.java.swing.MenuSelectionManager;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.RadioButtonMenuItemUI;
- import com.sun.java.swing.plaf.UIResource;
- import java.awt.AWTEvent;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.io.Serializable;
-
- public class BasicRadioButtonMenuItemUI extends RadioButtonMenuItemUI implements Serializable {
- protected static Color pressedBackground = null;
- protected static Color pressedForeground = null;
- protected Icon menuArrow = null;
- protected Icon checkIcon = null;
- protected static final int defaultTextIconGap = 4;
- protected MouseListener mouseListener;
- protected MouseMotionListener mouseMotionListener;
- protected boolean oldBorderPainted;
-
- protected void addListeners(JComponent c) {
- ((Component)c).addMouseListener(this.mouseListener);
- ((Component)c).addMouseMotionListener(this.mouseMotionListener);
- }
-
- protected MouseListener createMouseListener(JComponent c) {
- return new BasicMenuMouseListener();
- }
-
- protected MouseMotionListener createMouseMotionListener(JComponent c) {
- return new BasicMenuMouseMotionListener();
- }
-
- public static ComponentUI createUI(JComponent b) {
- return new BasicRadioButtonMenuItemUI();
- }
-
- public Insets getDefaultMargin(AbstractButton c) {
- return new Insets(2, 2, 2, 2);
- }
-
- public Dimension getMaximumSize(JComponent c) {
- return this.getPreferredSize(c);
- }
-
- public Dimension getMinimumSize(JComponent c) {
- return this.getPreferredSize(c);
- }
-
- public Dimension getPreferredSize(JComponent c) {
- return BasicGraphicsUtils.getPreferredMenuItemSize(c, this.checkIcon, this.menuArrow, 4);
- }
-
- protected void initListeners(JComponent c) {
- this.mouseListener = this.createMouseListener(c);
- this.mouseMotionListener = this.createMouseMotionListener(c);
- }
-
- public void installUI(JComponent c) {
- JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem)c;
- this.initListeners(c);
- this.addListeners(c);
- c.setOpaque(true);
- LookAndFeel.installBorder(c, "MenuItem.border");
- this.oldBorderPainted = ((AbstractButton)menuItem).isBorderPainted();
- ((AbstractButton)menuItem).setBorderPainted((Boolean)UIManager.get("MenuItem.borderPainted"));
- LookAndFeel.installColorsAndFont(c, "MenuItem.background", "MenuItem.foreground", "MenuItem.font");
- if (pressedBackground == null || pressedBackground instanceof UIResource) {
- pressedBackground = UIManager.getColor("MenuItem.pressedBackground");
- }
-
- if (pressedForeground == null || pressedForeground instanceof UIResource) {
- pressedForeground = UIManager.getColor("MenuItem.pressedForeground");
- }
-
- if (this.menuArrow == null || this.menuArrow instanceof UIResource) {
- this.menuArrow = UIManager.getIcon("MenuItem.arrowIcon");
- }
-
- if (((AbstractButton)menuItem).getSelectedIcon() == null || ((AbstractButton)menuItem).getSelectedIcon() instanceof UIResource) {
- ((AbstractButton)menuItem).setSelectedIcon(UIManager.getIcon("RadioButtonMenuItem.icon"));
- }
-
- }
-
- public void paint(Graphics g, JComponent c) {
- BasicGraphicsUtils.paintMenuItem(g, c, ((JRadioButtonMenuItem)c).getSelectedIcon(), this.menuArrow, pressedBackground, pressedForeground, 4);
- }
-
- public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path, MenuSelectionManager manager) {
- Point p = e.getPoint();
- if (p.x >= 0 && p.x < ((JComponent)item).getWidth() && p.y >= 0 && p.y < ((JComponent)item).getHeight()) {
- if (((AWTEvent)e).getID() == 502) {
- manager.clearSelectedPath();
- ((AbstractButton)item).doClick(0);
- item.setArmed(false);
- } else {
- manager.setSelectedPath(path);
- }
- } else if (((AbstractButton)item).getModel().isArmed()) {
- MenuElement[] newPath = new MenuElement[path.length - 1];
- int i = 0;
-
- for(int c = path.length - 1; i < c; ++i) {
- newPath[i] = path[i];
- }
-
- manager.setSelectedPath(newPath);
- }
-
- }
-
- protected void removeListeners(JComponent c) {
- ((Component)c).removeMouseListener(this.mouseListener);
- ((Component)c).removeMouseMotionListener(this.mouseMotionListener);
- }
-
- public void uninstallUI(JComponent c) {
- JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem)c;
- this.removeListeners(c);
- LookAndFeel.uninstallBorder(c);
- ((JMenuItem)c).setBorderPainted(this.oldBorderPainted);
- if (this.menuArrow instanceof UIResource) {
- this.menuArrow = null;
- }
-
- if (this.checkIcon instanceof UIResource) {
- this.checkIcon = null;
- }
-
- if (((AbstractButton)menuItem).getSelectedIcon() instanceof UIResource) {
- ((AbstractButton)menuItem).setSelectedIcon((Icon)null);
- }
-
- }
-
- public void update(Graphics g, JComponent c) {
- this.paint(g, c);
- }
- }
-